﻿
    <style type="text/css">
		.pull-right {
		    float: right !important;
		    display: inline-flex;
		}
		.searBOX .inpBox input.inptext, .searBOX .inpBox .selsty {
    		width: auto;
    	}
    	
    	.chartU{text-align: center;}
    	.chart{
    		width: 500px;
    		height:500px;
    		display: inline-block;
    		margin: 8px;
    		border: 1px solid #E8E8E8;
    	}
	</style>
	
    <div class="inner_line">
	    <div class="mainBOX ">
			<ul id="tab">
	    		<li class="current">组织建设</li>
	    		<li id="tqtj_li">团情统计</li>
	    		<li id="dkgg_li">打卡管理</li>
	    		<li id="tzgg_li">通知公告</li>
	    	</ul>
	        <div id="content">
				<div class="tabUI" style="display:block;">
	            	<div class="chartU" ng-controller="ZzjsCtrl as ctrl" ng-init="ctrl.query()">
	            		<div id="tzbfb" class="chart"></div>
	            		<div id="tgbfb" class="chart"></div>
	            		<div id="tgbxlfb" class="chart"></div>
	            		<div id="tgbnlfb" class="chart"></div>
	            		<div id="tyfb" class="chart"></div>
	            		<div id="tyrdfb" class="chart"></div>
	            	</div>
	            </div>
	            <div class="tabUI">
	            	<div class="chartU"></div>
				</div>
				<div id="dkgg_tab" class="tabUI">
					<div class="chartU" ng-controller="DkggCtrl as ctrl" ng-init="ctrl.query()">
						<div class="cooBOX">
							<a href="javascript:;" class="btn addBtn" ng-click="ctrl.add()">添加</a>
							<a href="javascript:;" class="btn addBtn" ng-click="ctrl.query()">刷新</a>
						</div>
						<table class="newTABLE">
							<thead>
							<th style="width: 3%" class="selBOX"><input ng-change="changeAll()" ng-model="selectAll" type="checkbox"></th>
							<th style="width: 27%">工号/学号</th>
							<th style="width: 27%">姓名</th>
							<th style="width: 18%">操作</th>
							</thead>
							<tr ng-repeat="item in ctrl.entities.content" ng-init="outerIndex=$index" ng-click="changeCurrents(item, $event)">
								<td class="selBOX"><input ng-model="item.checked" ng-click="changeCurrent(item, $event)" type="checkbox"></td>
								<td>{{item.kqyh}}</td>
								<td>{{item.kqy}}</td>
								<td>
									<a href="javascript:;" class="btn_w clear" ng-click="ctrl.del(item)">删除</a>
								</td>
							</tr>
						</table>
						<div class="panel-body">
							共有记录：
							<span>{{ctrl.entities.totalElements}}</span>
							条
							<div class="pull-right" ng-include="':root/components/page.html'"></div>
						</div>
					</div>
	            </div>
				<div id="tzgg_tab" class="tabUI">
	     			<div class="chartU" ng-controller="TzggCtrl as ctrl" ng-init="ctrl.query()">
	            		<div class="searBOX">    
		            		<div class="inpBox">
		            			<span class="left">标题：</span>
		            			<input type="text" class="inptext" placeholder="标题" ng-model="ctrl.btQueryParam">
		            		</div>
							<div class="inpBox">
								<span class="left">发布人：</span>
								<input type="text" class="inptext" class="inptext" placeholder="发布人" ng-model="ctrl.fbrQueryParam">
		            		</div>
		            		<div class="inpBox"> 
		            			<span class="left">发布状态：</span>
		            			<select class="form-control selsty" chosen ng-model="ctrl.fbztQueryParam">
		              				<option value="">---请选择---</option>
									<option value="0">未发布</option>
		              				<option value="1">已发布</option>
		            			</select>
		            		</div>
							<a href="javascript:;" ng-click="ctrl.query()" type="submit" class="btn checkBtn">查询</a>
		            		<a href="javascript:;" ng-click="ctrl.reset()" type="reset" class="btn resrtBtn">重置</a>
						</div>
		            	<div class="cooBOX"> 
		            		<a href="javascript:;" class="btn addBtn" ng-click="ctrl.add('')">新增</a>
		            		<a href="javascript:;" class="btn clearBtn" ng-click="ctrl.delAll()">批量删除</a>
		            	</div>
		            	<table class="newTABLE">
			              	<thead>
				                <th style="width: 3%" class="selBOX"><input ng-change="changeAll()" ng-model="selectAll" type="checkbox"></th>
				                <th style="width: 27%">标题</th>
				                <th style="width: 8%">发布人</th>
				                <th style="width: 8%">创建人</th>
				                <th style="width: 10%">创建时间</th>
				                <th style="width: 8%">修改人</th>
				                <th style="width: 10%">修改时间</th>
				                <th style="width: 8%">发布状态</th>
				                <th style="width: 18%">操作</th>
			              	</thead>
		              		<tr ng-repeat="item in ctrl.entities.content" ng-init="outerIndex=$index" ng-click="changeCurrents(item, $event)">
			              		<td class="selBOX"><input ng-model="item.checked" ng-click="changeCurrent(item, $event)" type="checkbox"></td>
				              	<td>{{item.bt}}</td>
				              	<td>{{item.fbr}}</td>
				              	<td>{{item.cjr}}</td>
				              	<td class="fc_gery">{{item.cjsj}}</td>
				              	<td>{{item.xgr}}</td>
				              	<td class="fc_gery">{{item.xgsj}}</td>
				              	<td class="fc_gery">{{item.fbzt=='1'?'已发布':'未发布'}}</td>
				              	<td>
					              	<a href="javascript:;" class="btn_w eidt" ng-click="ctrl.preview(item)" >预览</a><!-- ui-sref="app.newsview({id:item.id})" -->
					              	<a href="javascript:;" class="btn_w eidt" ng-click="ctrl.edit(item)" ng-if="item.fbzt=='0'">编辑</a>
					              	<a href="javascript:;" class="btn_w clear" ng-click="ctrl.del(item)">删除</a>
					              	<a href="javascript:;" class="btn_w release" ng-click="ctrl.publish(item,1)" ng-if="item.fbzt=='0'">发布</a>
					              	<a href="javascript:;" class="btn_w release" ng-click="ctrl.publish(item,0)" ng-if="item.fbzt=='1'">撤销发布</a>
			              		</td>
			              	</tr>
		            	</table>
		            	<div class="panel-body">
							共有记录：
							<span>{{ctrl.entities.totalElements}}</span>
							条
							<div class="pull-right" ng-include="':root/components/page.html'"></div>
						</div>
	          		</div>
				</div>
			</div>
	   	</div>
	</div>
   
	<!-- js -->
    <!-- <script type="text/javascript" data-main="asset/main.js" src="asset/js/require.min.js"></script>
    <script type="text/javascript" src="asset/js/include.js"></script>
    <script type="text/javascript" src="asset/jquery/jquery.js"></script>
    <script type="text/javascript" src="asset/js/comm.js"></script>
    <script type="text/javascript" src="asset/js/banner.js"></script> -->
	<script type="text/javascript" src="asset/js/ctrl-dkgg.js"></script>
	<script type="text/javascript" src="asset/js/ctrl-zzjs.js"></script>

    <script>
    $(function(){
		var $li = $('#tab li');
		var $ul = $('#content .tabUI');
					
		$li.click(function(){
			var $this = $(this);
			var $t = $this.index();
			$li.removeClass();
			$this.addClass('current');
			$ul.css('display','none');
			$ul.eq($t).css('display','block');
		})
		
		$('#tqtj_li').on('click',function(){
			location.href = '#/manager/tyxxcjAudit';
		});
    });
    
		function TzggCtrl($injector,$scope, CtrlUtil, $element,modalService, $http,$state) {
			var ctrl = this;
			var listUrl = ':root/tzgggl/list';
			
			//CtrlUtil.build(this, listUrl)
			this.query = function () {
				ctrl.entities && (ctrl.entities.content = {})
				var p = CtrlUtil.getQueryParams(ctrl)
				$http.post(listUrl, p).success(function (r) {
					ctrl.entities = r;
				})
			}
			this.reset = function() {
				CtrlUtil.resetQueryParams(ctrl);
			};
			this.preview = function (item) {
				//$state.go('app.newsview',{id:item.id});
				var url = 'newsview.html?id='+item.id;
				//location.href = url;
				window.open(url);
			}
			this.add = function (id) {
				var isEdit = true;console.log(id)
				if(id==''){
					id = guid();
					isEdit = false;
				}
				location.href = 'newsedit.html?id='+id+'&isEdit='+isEdit;
			}
			this.edit = function (item) {
				ctrl.add(item.id)
			}
			this.del = function (item) {
				//var modalService = $injector.get('modalService');
				modalService.confirm({
					content: '确定要删除' + item.bt + '吗?',
					result: item
				}).then(function (r) {
					$http.post(':root/tzgggl/deleteTzzg', r).success(function (R) {
						modalService.succ('删除成功', 1500)
						ctrl.refresh()
						ctrl.query()
					})
				})
			}
			this.publish = function (item,fbzt){
				//var modalService = $injector.get('modalService');
				var title = '发布';
				if(fbzt==0){
					title = '撤销发布';
				}
				modalService.confirm({
					content: '确定要' + title + item.bt + '吗?'
				}).then(function (r) {
					$http.post(':root/tzgggl/publishTzzg', {
						id : item.id,
						fbzt : fbzt
					}).success(function (R) {
						modalService.succ('操作成功', 1500)
						ctrl.refresh()
						ctrl.query()
					})
				})
			}
			
			//记录行单选及多选处理
			$scope.count = 0;//已选择数量 
			$scope.selectData = [];//已选对象
			//选择单个（取消选择单个
            $scope.changeCurrent = function(current, $event) {
              	//计算已选数量 true加， false减
                $scope.count += current.checked ? 1 : -1;
                //判断是否全选，选数量等于数据长度为true
        		$scope.selectAll = $scope.count === ctrl.entities.content.length;
                //统计已选对象
                $scope.selectData = [];
                angular.forEach(ctrl.entities.content, function(item) {
                    if(item.checked){
                    	$scope.selectData[$scope.selectData.length] = item.id;
                    }
                });
              	$event.stopPropagation();//阻止冒泡
            };

            //单击行选中
            $scope.changeCurrents = function(current, $event) {
                if(current.checked == undefined){
                    current.checked = true;
                }else{
                    current.checked = !current.checked;
                }
                $scope.changeCurrent(current, $event);
            };

       		//全选（取消全选
            $scope.changeAll = function() {
                angular.forEach(ctrl.entities.content, function(item) {
                    item.checked = $scope.selectAll;
                    $scope.selectData[$scope.selectData.length] = item.id;
                });
                $scope.count = $scope.selectAll ? ctrl.entities.content.length : 0;
                if ($scope.selectAll) {
                	//$scope.selectData = ctrl.entities.content;
                } else {
                	$scope.selectData = [];
                }
            };
            
            this.delAll = function () {
            	//var modalService = $injector.get('modalService');
            	console.log($scope.selectData.toString())
            	if($scope.count < 1){
            		modalService.error('请选择记录', 1500)
            		return;
            	}
				
            	modalService.confirm({
					content: '确定要删除所选记录吗?'
				}).then(function (r) {
					$http.post(':root/tzgggl/deleteAllTzzg', {
						result : $scope.selectData.toString()
					}).success(function (R) {
						modalService.succ('删除成功', 1500)
						$scope.count = 0;
						$scope.selectData = [];
						ctrl.refresh()
						ctrl.query()
					})
				})
			}
            
            this.refresh = function () {
            	//设置显示tab页
				$("#tab li").removeClass("current");
				$('.tabUI').css('display','none');
				$('#tzgg_li').attr('class','current');
				$('#tzgg_tab').css('display','block');
            }
            
            if(undefined != getParam('isBack') && getParam('isBack') == '4'){
				ctrl.refresh()
			}
		}
	</script>
